package com.niit.musicserver.controller;

import com.niit.musicserver.common.Result;
import com.niit.musicserver.constant.enums.ExceptionCodeEnum;
import com.niit.musicserver.entity.domain.User;
import com.niit.musicserver.exception.MusicException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

//@Controller
//@ResponseBody //以json数据返回
@RestController//等价于 @Controller+@ResponseBody

public class UserController {

    /**
     * @Description:
     * @Author: cheng_jianzhen
     * @CreateTime: 2024/1/16 10:52
     * @return: java.lang.String
     **/


    @GetMapping("/user")
    public String hello(){
        System.out.println("hello world!");
        return "hello";
    }

    @GetMapping("/user/{id}")
//    public User getUserId(@PathVariable Integer id) {
    public Result getUserId(@PathVariable Integer id) {
//        try {
            System.out.println("要获取的用户id：   " + id);
//            int a=0;
//            int b = 2 / a;
            //T0D0需要查询数据库d
            User user = new User();
            user.setId(id);
            user.setUserName("张三");
            user.setIntroduction("简介");
//        }catch (Exception e){
//            e.printStackTrace();
//            return Result.faile(ExceptionCodeEnum.COMMON_ERROR);
//        }
        if (null != id && id > 0 && null != user){
            throw new MusicException("当前用户已存在，请更改");
//            return Result.success("请求成功",user);
        }
//        return user;
//        return Result.faile(9001,"未查询到数据");
//        return Result.faile(ExceptionCodeEnum.NO_RESULT_DATA.getResCode(),ExceptionCodeEnum.NO_RESULT_DATA.getResDesc());
        return Result.faile(ExceptionCodeEnum.NO_RESULT_DATA);

    }
}
